home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / asppw112 / fupload.asp < prev    next >
Text File  |  1999-01-12  |  6KB  |  166 lines

  1. <%
  2.     ' This file is provided as part of  ASP Power Widgets Samples
  3.     '
  4.     ' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT
  5.     ' WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
  6.     ' INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES
  7.     ' OF MERCHANTABILITY AND/OR FITNESS FOR A  PARTICULAR
  8.     ' PURPOSE.
  9.  
  10.     ' Copyright 1997-1998. All rights reserved.
  11.     ' Dalun Software Inc. ASP Power Widgets
  12.     ' http://dalun.com 
  13.     ' mail: sales@dalun.com
  14.     ' mail: techsupport@dalun.com
  15.     ' if you have any suggestions or requirements, please write to us.
  16.     ' Please set your editor's TAB as 4.
  17.     ' Revisions:
  18.     ' 1.00   Initial release
  19.     ' 1.10   Added reading form items.
  20.     ' 1.11   Added oUpload.Form, added oUpload.UploadedFiles(i).FormName
  21. %>
  22.  
  23. <HTML><HEAD><TITLE>File Upload Test</TITLE></HEAD>
  24.  
  25. <BODY TEXT="gray" LINK="silver" VLINK="silver" BGCOLOR="Gray">
  26. <BR><BR>
  27.  
  28. <CENTER>
  29. <FONT FACE ="Verdana, Arial, Helvetica" SIZE="2" COLOR="silver">
  30. <%
  31.  
  32. if Request.querystring("Status") = 1 then
  33.     Set oUpload = Server.CreateObject("ASPPW.upload")
  34.     oUpload.UserDiskQuota= 2 * 1024 * 1024
  35.     oUpload.RejectEmptyExtension = true
  36.     oUpload.FileExtensionList "*","txt", "gif" ,"jpg"     'remove '*', if you don't allow all types
  37.     oUpload.UpLoadPath = server.mappath("/") + "\test"
  38.     i=oUpload.Upload
  39.     Select Case i
  40.         case  1
  41.             sMsg = "File uploading ends normally."
  42.         Case -4
  43.             sMsg = "User's Disk Quota full. At least one file hasn't been saved."
  44.         Case -5
  45.             sMsg = "Path on server for uploading not found or invalid."
  46.         Case -6
  47.             sMsg = "File type for uploading is not allowed. At least one file hasn't been saved."
  48.         Case -7
  49.             sMsg = "Uploading exception."
  50.         Case -8
  51.             sMsg = "File access failure."
  52.  
  53.         case else
  54.             sMsg = "Exception. Error Code is: " & cstr(i) & "."
  55.       End Select
  56.  
  57.     response.write sMsg + "<br>"
  58.     response.write cstr(oUpload.NumofUploadedFiles) + " file(s) uploaded. <br>"
  59.  
  60.     if oUpload.GetLastErrNum <> 0 then
  61.         response.write  oUpload.GetLastErrDescription
  62.     end if
  63.  
  64.  
  65.     set oFiles = oUpload.UploadedFiles    'return a Collection
  66.     'response.write oFiles.count          'Sample operation to a collection
  67.     'response.write oFiles.item(1)        'Sample operation to a collection
  68.  
  69.     set oForm = oUpload.Form              'return a Collection
  70.  
  71. %>
  72.  
  73.     <table width="66%" border="1">
  74.     <% for each file in oFiles %>
  75.     <tr>
  76.         <td><FONT FACE ="Verdana, Arial, Helvetica" SIZE="2" COLOR="silver"><%=file.filename%></font></td>
  77.         <td><FONT FACE ="Verdana, Arial, Helvetica" SIZE="2" COLOR="silver"><%=file.filelen%></font></td>
  78.         <td><FONT FACE ="Verdana, Arial, Helvetica" SIZE="2" COLOR="silver"><%=file.formname%></font></td>
  79.         <td><FONT FACE ="Verdana, Arial, Helvetica" SIZE="2" COLOR="silver"><%=oform(file.formname)%></font></td>
  80.     </tr>
  81.     <% next %></FONT>
  82.     </table>
  83. <%
  84.     set oFiles = nothing
  85.     set oForm =  nothing
  86. %>
  87.  
  88. <%
  89.     set oFormItems = oUpload.FormItems    'return a Collection
  90.     'Note: oFormItems is another way to fetch form items.
  91. %>
  92.     <p><FONT FACE ="Verdana, Arial, Helvetica" SIZE="2" COLOR="silver">
  93.     Demonstration of fetching form items:</font>
  94.  
  95.     <table width="66%" border="1">
  96.     <% for each item in oFormItems %>
  97.     <tr>
  98.         <td><FONT FACE ="Verdana, Arial, Helvetica" SIZE="2" COLOR="silver"><%=item.name%></font></td>
  99.         <td><FONT FACE ="Verdana, Arial, Helvetica" SIZE="2" COLOR="silver"><%=item.value%></font></td>
  100.     </tr>
  101.     <% next %></FONT>
  102.     </table>
  103. <%
  104.     set oFormItems = nothing
  105. %> 
  106.  
  107. <%
  108.     set oUpload = nothing
  109. end if
  110. %>
  111. </font>
  112.  
  113. <FORM NAME=up ACTION="fupload.asp?Status=1" METHOD="POST" ENCTYPE="multipart/form-data">
  114.  
  115. <!-- You can specify the filenames for uploaded files as below
  116.      ServerName1 ...99 
  117. <FORM NAME=up ACTION="fupload.asp?Status=1&ServerName1='aa 1.gif'&ServerName2='bb 2.gif'" METHOD="POST" ENCTYPE="multipart/form-data">
  118. -->
  119. <TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0 BGCOLOR="Gray" WIDTH=400>
  120.  
  121. <TR><TD>
  122. <FONT FACE ="Verdana, Arial, Helvetica" SIZE="2" COLOR="silver">
  123. UpLoad Test<BR>
  124. </FONT><BR> </TR></TD><TR>
  125. <TD BGCOLOR="Silver" WIDTH=400>
  126. <FONT SIZE="1" COLOR="gray" FACE="Verdana, Arial, Helvetica"> 
  127. UPLOAD FILE</FONT>
  128. </TD></TR>
  129.  
  130. <!-- Remove below form item if you don't need it.  -->
  131. <TR><TD>
  132. <INPUT TYPE=HIDDEN SIZE=36 NAME="Org_Code" VALUE="Research Dept.">
  133. </TD></TR>
  134. <!-- Remove above form item if you don't need it.  -->
  135.  
  136. <!-- Remove below form item if you don't need it.  -->
  137. <TR><TD>
  138. <INPUT TYPE=HIDDEN SIZE=36 NAME="uplfile1" VALUE="From Research Dept.">
  139. </TD></TR>
  140. <!-- Remove above form item if you don't need it.  -->
  141.  
  142. <!-- Remove below form item if you don't need it.  -->
  143. <TR><TD>
  144. <INPUT TYPE=HIDDEN SIZE=36 NAME="uplfile2" VALUE="From Development Dept.">
  145. </TD></TR>
  146. <!-- Remove above form item if you don't need it.  -->
  147.  
  148. <TR><TD>
  149. <INPUT TYPE=FILE SIZE=36 NAME="uplfile1">   <!-- ServerName1  -->
  150. </TD></TR>
  151.  
  152. <TR><TD>
  153. <INPUT TYPE=FILE SIZE=36 NAME="uplfile2">   <!-- ServerName2  -->
  154. </TD></TR>
  155.  
  156. <!-- You can add more if you want to upload more files at a single time  -->
  157.  
  158. <TR><TD ALIGN="RIGHT">
  159. <FONT SIZE="1" COLOR="silver" FACE="Verdana, Arial, Helvetica">Dalun Software, Inc.
  160. <B>[<A HREF="javascript:document.up.submit();"><B> S U B M I T </B></A>]</FONT>
  161. </TD></TR>
  162. </TABLE></FORM>
  163.  
  164. </CENTER>
  165. </BODY></HTML>
  166.